var pageii = null;
var grid = null;

$(function () {

    grid = lyGrid({
        pagId: 'paging',
        l_column: [{
            colkey: "id",
            name: "id",
            hide:true
        },{
            colkey: 'title',
            name: '选项名'
        }, {
            colkey: 'questionName',
            name: '所属题目'
        }],
        jsonUrl: rootPath + '/app/diagnosis/findAnswerByPage.shtml?question_id='+question_id,
        dymCol: true,
        checkbox: true,
        serNumber: true,
        usePage:false
    });
    $('#search').click('click', function () { // 绑定查询按扭
        var searchParams = $('#searchForm').serializeJson(); // 初始化传参数
        grid.setOptions({
            data: searchParams
        });
    });

    if(selectetAnswerIds.length>0){
        initCheckBox(selectetAnswerIds.split(","))
    }

    function initCheckBox(checkData){
        $("input[type='checkbox']").each(function(){
            for(var j=0;j<checkData.length;j++){console.log($(this).val()+"====");
                if($(this).val() == checkData[j] ){
                    $(this).attr("checked","checked");
                }
            }
        });
    }

});




function addSelected(obj) {
    var cbox = grid.getSelectedCheckbox();
    if (cbox == "") {
        layer.msg("请选择关联项！！");
        return;
    }
    var ids =cbox.join(",");
    var row = grid.selectRow();
    var names="";
    for (let i = 0; i <row.length ; i++) {
        if(i==row.length-1){
            names+=row[i].title;
        }else{
            names+=row[i].title+",";
        }

    }

    window.parent.document.getElementById("reply_answer_ids").value= ids;
    window.parent.document.getElementById("reply_answer_names").value= names;

    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
}